package servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspWriter;

import Database.MySQLController;
import Model.DeviationNotes;

@WebServlet("/NotesDropDown")
public class DeviationNotesDropDown extends HttpServlet {
	private static final long serialVersionUID = 1L;
    JspWriter out;   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeviationNotesDropDown() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    public DeviationNotesDropDown(JspWriter outputStream) {
		// TODO Auto-generated constructor stub
		out = outputStream;
	}
    /**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		ArrayList<DeviationNotes> NotesList = new ArrayList<DeviationNotes>();
		NotesList = Database.DeviationNotesDB.GetManual();
		
		for(int i = 0; i < NotesList.size(); i++)
		{
			System.out.println("<option value='" + NotesList.get(i).getId() + "'>");
			out.print("<option value='" + NotesList.get(i).getId() + "'>");
				out.print(NotesList.get(i).getName());
			out.print("</option>");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
	}
	
	public int deleteDeviationNotes(String deviationNoteTitle)
	{
		MySQLController mysql = new MySQLController();
		mysql.setUp();
		int j1=0; 
		try
		{ 
			String dbQuery="DELETE FROM deviationnotes WHERE idDeviationNotes='"+deviationNoteTitle+"'"; 
			j1 = mysql.updateRequest(dbQuery);
		}catch(SQLException sqlEx)
		{
			sqlEx.printStackTrace();
		}finally
		{
			mysql.terminate();
		}
		return j1;
	}
}